package com.mysqldemo.service.serviceImpl;
import javax.annotation.Resource;
import com.mysqldemo.mappers.InfoMapper;

import com.mysqldemo.service.InfoService;

import com.mysqldemo.entity.po.Info;

import com.mysqldemo.entity.query.InfoQuery;

import com.mysqldemo.entity.vo.PaginationResultVO;

import org.springframework.stereotype.Service;

import java.util.List;

import com.mysqldemo.enums.PageSize;

import com.mysqldemo.entity.query.SimplePage;

/**
 * @Description Mapper
 * @Author 徐大勇
 * @Version 1.8.0_131
 * @date 2023/07/06
 */
@Service("InfoService")
public class InfoServiceImpl implements InfoService {

	@Resource
	private InfoMapper<Info,InfoQuery> InfoMapper;

	@Override
//通过InfoQuery查询
	public List<Info> selectByParam(InfoQuery query){
		return this.InfoMapper.selectList(query);
	}

	@Override
//通过条件查询数量
	public Integer selectCountByParam(InfoQuery query){
		return this.InfoMapper.selectCount(query);
	}

	@Override
//分页查询
	public PaginationResultVO<Info> findListByPage(InfoQuery query){
		Integer count = this.selectCountByParam(query);
		int pageSzie = query.getPageSize() == null? PageSize.SIZE15.getSize():query.getPageSize();
		SimplePage page = new SimplePage(query.getPageNo(),count,pageSzie);
		List<Info> list = this.selectByParam(query);
		PaginationResultVO<Info> resultVO = new PaginationResultVO<>(count,page.getPageSize(),page.getPageNo(),list);
		return  resultVO;

	}

	@Override
//插入
	public Integer add(Info bean){
		return this.InfoMapper.insert(bean);
	}

	@Override
//批量插入
	public Integer addBatch(List<Info> list){
		if(list == null || list.size() == 0){
			return 0;
		}
		return this.InfoMapper.insertBatch(list);
	}
	@Override
//批量插入或更新
	public Integer addOrUpdateBatch(List<Info> list){
		if(list == null || list.size() == 0){
			return 0;
		}
		return this.InfoMapper.updateOrInsert(list);
	}


	@Override
//通过UserId查询
	public Info getByUserId(String userId) {
		return this.InfoMapper.selectByUserId(userId);
	}

	@Override
//通过UserId更新
	public Integer updateByUserId(Info bean , String userId) {
		return this.InfoMapper.updateByUserId(bean,userId);
	}

	@Override
//通过UserId删除
	public Integer deleteByUserId(String userId) {
		return this.InfoMapper.deleteByUserId(userId);
	}

}
